using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;

[RequireComponent(typeof(ActiveObject))]
public class CutSceneTrigger : MonoBehaviour
{
    [SerializeField] private PlayableDirector cutScene;

    private ActiveObject active;
    private PlayerController player;
    [SerializeField] private AudioSource AudiComponet;

    private void Start()
    {
        active = GetComponent<ActiveObject>();
    }
    private void OnTriggerEnter2D(Collider2D collision)
    {
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
        player.Sleeeeeep();
        cutScene.Play();
        StartCoroutine(PlayAnim());
        //PlayerData.RemoveTask(NameLib.FirstSleep);
        StartCoroutine(StopMusic());
    }

    private IEnumerator PlayAnim()
    {
        yield return new WaitForSeconds((float)cutScene.duration);
        player.OnCanInteractive(true);
       // active.IsDisactive();
    }
    private IEnumerator StopMusic()
    {
        AudiComponet.volume = 0;
        yield return new WaitForSeconds(38);
        AudiComponet.volume = 0.5f;
        active.IsDisactive();

    }
}
